package cate.game.play.skill.passive.fairy;

import cate.common.table.d.GDAttr;
import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.proce.turn.TurnCtx;
import cate.game.play.skill.passive.PassiveHandler;
import cate.game.play.skill.passive.hero.审判之箭PH;

import java.util.List;

/**
 * 效果1："百步穿杨”技能系数提升12%, 对处于控制状态的目标额外造成7%最大生命值的真实伤害，若目标处于[冰冻]状态则提升10%(强化)
 * 效果2：出手时触发物连或者被闪避获得1层[冰凝箭]， 每层提升15%攻击力，持续3回合且不可驱散
 * 效果3： "觅心箭羽"技能系数提升12%,对前排目标额外提升10%伤害，为后排目标附加[易损]，降低10%暴击伤害，持续2回合(强化)
 * 效果4：第4、8、12回合首次出手后额外对血量最低的敌方单位发射"审判之箭"，并增加自身10%物连概率(需携带物连，可叠加)
 */
public class 蓝纹奶酪灵器PH extends PassiveHandler {


	private int 冰凝箭buff;

	private List<Integer> 触发回合;

	private FightAttr 属性提升;


	//冰凝箭buff=？？&触发回合=4#8#12&属性提升=1010:1000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		冰凝箭buff = args.getInt("冰凝箭buff", 0);
		触发回合 = args.getIntList("触发回合");
		属性提升 = new FightAttr(args.get("属性提升"));
	}

	private 审判之箭PH 审判之箭ph;

	@Override
	public void onFirstEnter(ActionCtx action) {
		for (PassiveHandler handler : skill.owner.skill.getHandlers()) {
			if(handler instanceof 审判之箭PH){
				审判之箭ph = (审判之箭PH)handler;
				break;
			}
		}
	}

	@Override
	public void onMissAsTarget(SkillActionCtx action) {
		skill.owner.buff.tryAddByTid(action, 冰凝箭buff);
	}

	@Override
	public void onDoubleAct(TurnCtx turn, TimeActionCtx action, Fighter fighter, int passiveSkill) {
		if (fighter.getPid() == skill.owner.getPid()) {
			skill.owner.buff.tryAddByTid(action, 冰凝箭buff);
		}
	}

	private boolean roundAppend;

	@Override
	public void onRoundBegin(ActionCtx action) {
		roundAppend = false;
	}

	@Override
	public void onOwnerMoveDone(MoveCtx move, TimeActionCtx action) {
		if (审判之箭ph == null) {
			return;
		}
		if (move.isAppend()) {
			return;
		}
		if (roundAppend) {
			return;
		}
		if (XT.isBlank(触发回合)) {
			return;
		}
		if (!触发回合.contains(move.getRound().index)) {
			return;
		}
		Fighter target = TargetSelector.findOne(skill.owner, move.getTeamVS(), new TargetFilterParam().smallAttrSet(GDAttr.V_HP_LEFT_RATE));
		if (target == null) {
			return;
		}
		roundAppend = true;
		审判之箭ph.addAppendMove(move, target);
		skill.owner.attr.addAttr(属性提升);
	}
}
